<!DOCTYPE html>
<html>
<head>
	<!-- 公共页面 -->
	#include("../include/common.html")
	<!-- 公共页面 /-->
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div class="wrapper">
        <!-- 页面头部 -->
        #include("../include/header.html")
        <!-- 页面头部 /-->
        <!-- 导航侧栏 -->
        #include("../include/menu.html")
        <!-- 导航侧栏 /-->
        <!-- 内容区域 -->
        <div class="content-wrapper" id="contentDiv">
            <!-- 正文区域 -->
            <section class="content">
				<!-- .box-body -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">数据库管理</h3>
                    </div>
                    <div class="box-body">
                        <!-- 数据表格 -->
                        <div class="table-box">
                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" id="backup"><i class="fa fa-file-o"></i> 备份</button>
                                        <button type="button" class="btn btn-default" id="refreshButton"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <!--工具栏/-->
                            <!--数据列表-->
                            <table id="listTable" class="table table-bordered table-striped table-hover dataTable">
                                <thead>
                                    <tr>
                                        <th>名称</th>
	                                    <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="listTr">
                                	#for(backup : backups)
	                                <tr>
	                                    <td>#(backup)</td>
	                                    <td>
	                                        <button type="button" class="btn bg-olive btn-xs restore" val="#(backup)">还原</button>
                                            <button type="button" class="btn bg-olive btn-xs delete" val="#(backup)">删除</button>
	                                    </td>
	                                </tr>
	                                #end
                                </tbody>
                            </table>
                            <!--数据列表/-->
                        </div>
                        <!-- 数据表格 /-->
                    </div>
                    <!-- /.box-body -->
                </div>
            </section>
            <!-- 正文区域 /-->
        </div>
        <!-- 内容区域 /-->
        <!-- 底部导航 -->
        #include("../include/footer.html")
        <!-- 底部导航 /-->
    </div>
</body>
</html>
<!---->
<script>
 $(document).ready(function() {
     // 激活导航位置
     setSidebarActive("admin-database");
 });
</script>
<script type="text/javascript">
$().ready(function() {

    var $backup = $("#backup");
    //备份
    $backup.click(function() {
    	swal({title:'', text:'正在备份中',icon: 'info' ,button:false});
        $.ajax({
            url: "#(base)/admin/database/backup",
            type: "POST",
            data: {},
            dataType: "json",
            cache: false,
            success: function(response) {
            	if(response.type=="success"){
            		swal({title:'', text:'备份完成',icon: 'success' }).then(function() {
                        location.reload();
                    });
            	}else{
            		swal({title:'', text:response.msg,icon: 'error' });
            	}
            }
        });
        return false;
    });
    
    //还原
    $(".restore").on("click",function(){
    	var $this = $(this);
    	var name = $this.attr("val");
    	swal({title:'', text:'正在还原中',icon: 'info' ,button:false});
        $.ajax({
            url: "#(base)/admin/database/restore",
            type: "POST",
            data: {name:name},
            dataType: "json",
            cache: false,
            success: function(response) {
            	if(response.type=="success"){
                    swal({title:'', text:'还原完成',icon: 'success' });
                }else{
                    swal({title:'', text:response.msg,icon: 'error' });
                }
            }
        });
        return false;
    });
    
    //删除
    $(".delete").on("click",function(){
        var $this = $(this);
        var name = $this.attr("val");
        $.ajax({
            url: "#(base)/admin/database/delete",
            type: "POST",
            data: {name:name},
            dataType: "json",
            cache: false,
            success: function(response) {
                if(response.type=="success"){
                	swal({title:'', text:'操作成功',icon: 'success' }).then(function() {
                        location.reload();
                    });
                }else{
                    swal({title:'', text:response.msg,icon: 'error' });
                }
            }
        });
        return false;
    });

});
</script>